<!-- Copyright (c) 2022 渝州大数据实验室
 *
 * Lanius is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *
 *     http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
-->
<!-- 
* @desc:任务编排搜索组件
* @fileName:ArrangementSearch.vue
* @author:chenxiaofeng@yzbdl.ac.cn
* @date:2022-4-8
!-->
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { Search, Plus } from "@element-plus/icons-vue";
import { useRoute } from "vue-router";
const route = useRoute();
// 接受父组件传回
const props = defineProps({
  // 查询方法
  searchFunc: Function as any,
  //弹窗显示方法
  dialogControlFunc: Function as any,
});

// 定义名称值
let userValue = ref("");

// 定义资源类型选择值
let eventValue = ref("");

/**
 * 资源类型下拉框选择项
 */
const options = [
  {
    value: "1",
    label: "已禁用",
  },
  {
    value: "2",
    label: "已启用",
  },
];

/**
 * 查询方法
 * @reture viod
 */
const onSerarch = () => {
  let searchData = {
    keyword: userValue.value,
    status: eventValue.value,
  };
  props.searchFunc(searchData);
};

/**
 * 新增方法
 * @reture viod
 */
const onAdd = () => {
  props.dialogControlFunc();
};

onMounted(() => {
  let queryVal: any = route.query.status;
  if (queryVal !== undefined) {
    eventValue.value = queryVal;
  }
});
</script>

<template>
  <div class="page-search">
    <!-- 名称查询 -->
    <el-input
      class="page-search-userInput"
      v-model="userValue"
      clearable
      @clear="onSerarch"
      @keyup.enter.native="onSerarch"
      :suffix-icon="Search"
      placeholder="请输入任务名称/服务节点/资源名称"
    ></el-input>
    <!-- 资源类型 -->
    <el-select
      class="page-search-eventChoose"
      v-model="eventValue"
      placeholder="请选择状态"
      clearable
      @change="onSerarch"
      size="large"
    >
      <el-option
        v-for="item in options"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      />
    </el-select>
    <el-button :icon="Plus" @click="onAdd">新增</el-button>
  </div>
</template>

<style scoped lang="scss">
.page-search {
  margin-bottom: 15px;
  display: flex;
  justify-content: end;

  :deep(.el-input__wrapper) {
    height: 30px;
    border-radius: 0;
    background-color: #f2f2f6 !important;
    box-shadow: unset !important;
  }
  :deep(.el-range-input) {
    background-color: #f2f2f6 !important;
  }
  .page-search-userInput {
    width: 310px;
    margin-right: 0;
  }
  .page-search-eventChoose {
    width: 160px;
    margin-left: 10px;
  }
  .el-button {
    margin-left: 10px;
    width: 70px;
    height: 30px;
    border-radius: 0;
    background-color: #f2f2f6;
    color: #000;
    border: 0;
    &:hover {
      background-color: #5473e6;
      color: #fff;
    }
  }
}
</style>
